package com.dongdongqiang.daogenerator.validator.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 表单验证注解
 * Created by zhangzhenbin on 2016/10/12.
 */
@Target({ ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface ValidateString {
    enum ValidatorMethod{
        REQUIRED("REQUIRED","","所填项为必填项"),
        MOBILE("MOBILE","^(13[0-9]|15[0-9]|17[0-9]|18[0-9]|14[0-9])[0-9]{8}$","手机号码格式错误"),
        NUMBER("NUMBER","^[0-9]*$","所填必须是整数"),
        POSINT("POSINT","^[1-9]\\d*$","所填必须是正整数"),
        TEL("TEL","^(0|86|17951)?(13[0-9]|15[0-9]|17[0-9]|18[0-9]|14[0-9])[0-9]{8}$","电话或手机号码格式错误"),
        IP("IP","^((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])$","ip地址格式错误"),
        MAIL("MAIL","^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$","邮件格式错误"),
        IDENTITY("IDENTITY","((11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|50|51|52|53|54|61|62|63|64|65|71|81|82|91)\\d{4})((((19|20)(([02468][048])|([13579][26]))0229))|((20[0-9][0-9])|(19[0-9][0-9]))((((0[1-9])|(1[0-2]))((0[1-9])|(1\\d)|(2[0-8])))|((((0[1,3-9])|(1[0-2]))(29|30))|(((0[13578])|(1[02]))31))))((\\d{3}(x|X))|(\\d{4}))","身份证格式错误"),
        CHINESE("CHINESE","^([\\u4E00-\\uFA29]|[\\uE7C7-\\uE7F3])*$","所填必须为中文"),
        URL("URL","^http[s]?://[\\w\\.\\-]+$","url验证失败"),
        BANKCARD("BANKCARD","^\\d{16}|\\d{17}|\\d{18}|\\d{19}$","银行卡验证失败"),
        PASSWORD("PASSWORD","^([\\w~a-z~A-Z~0-9]{6,16}$)|(.{32}$)","密码验证必须是字母、数字，长度在6~16位之间"),
        PAYPASSWORD("PAYPASSWORD","^(\\d{6})|(.{32}$)$","支付密码必须是6位数字"),
        YEAR("YEAR","[0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3}","年份格式验证失败"),
        LENIN("LENIN","^.{%d}$","所填长度必须在%d字节以内"),
        RATE("RATE","^(?:0|[1-9][0-9]?|100)$","比例必须是100内的数字")
        ;

        String code;    //code
        String pattern; //正则表达式
        String errorMsg;//错误提示

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getPattern() {
            return pattern;
        }

        public void setPattern(String pattern) {
            this.pattern = pattern;
        }

        public String getErrorMsg() {
            return errorMsg;
        }

        public void setErrorMsg(String errorMsg) {
            this.errorMsg = errorMsg;
        }

        ValidatorMethod(String code, String pattern, String errorMsg) {
            this.code = code;
            this.pattern = pattern;
            this.errorMsg = errorMsg;
        }
    }

    ValidatorMethod[] method() default {};
    int length() default 0; //最大长度
    String pattern() default "";
    String msg() default "所填项表单验证失败";
}
